package com.offcn.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.offcn.pojo.Checkgroup;

import com.offcn.service.CheckgroupService;
import com.offcn.utils.MessageConstant;
import com.offcn.utils.PageResult;
import com.offcn.utils.QueryPageBean;
import com.offcn.utils.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: wy
 * @Date: 2022/8/30 14:07
 */
@RestController
@RequestMapping("/checkgroup")
public class CheckgroupController {
    private Result result;


    @Reference
    private CheckgroupService checkgroupService;

    //添加
    @RequestMapping("/addGroup")
    public Result addGroup(@RequestBody Checkgroup checkgroup,
                           Integer[] checkitemIds) {

        try {
            checkgroupService.addGroup(checkgroup, checkitemIds);
            result = new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS, null);
        } catch (Exception e) {
            result = new Result(true, MessageConstant.ADD_CHECKGROUP_FAIL, null);
            throw new RuntimeException(e);
        }
        return result;
    }

    //分页查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return checkgroupService.findPage(queryPageBean);
    }


    //修改检查组的数据
    @RequestMapping("/editGroup")
    public Result editGroup(@RequestBody Checkgroup checkgroup,
                            Integer[] checkitemIds) {

        try {
            checkgroupService.editGroup(checkgroup, checkitemIds);
            result = new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS, null);
        } catch (Exception e) {
            result = new Result(true, MessageConstant.EDIT_CHECKGROUP_FAIL, null);
            throw new RuntimeException(e);
        }
        return result;
    }


    //删除
    @RequestMapping("deleteInfoByid")
    public Result deleteInfoByid(@RequestParam(value = "id") Integer id){
        try {
            checkgroupService.deleteInfoByid(id);
            result = new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS, null);
        } catch (Exception e) {
            result = new Result(true, MessageConstant.DELETE_CHECKGROUP_FAIL, null);
            throw new RuntimeException(e);
        }
        return result;
    }


    ////查询所有的检查组信息
    @RequestMapping("/showAllGroupInfo")
    public List<Checkgroup> showAllGroupInfo(){
        return checkgroupService.showAllGroupInfo();
    }


    //查询当前套餐 下的检查组信息
    @RequestMapping("/getGroupIdBySetmealId")
    public List<Integer> getGroupIdBySetmealId(@RequestParam(value = "id")Integer id){
        return checkgroupService.getGroupIdBySetmealId(id);
    }
}
